package com.hdustea.base.net

import io.reactivex.functions.Function
import com.hdustea.base.entity.Result

/**
 * @author Weimore
2018/12/6.
description:
 */
class CatchExceptionFunction<T> : Function<Result<T>, T> {

    @Throws(Exception::class)
    override fun apply(baseResult: Result<T>): T? {
        if (baseResult.code != 0) {
            throw Exception(baseResult.message)
        } else {
            return baseResult.data;
        }
    }

}